package com.it.zhangjun.arithmetic.贪心;

import java.util.Arrays;

/**
 * @author jun.zhang6
 * @date 2020/10/27
 */
public class 最优装载问题 {
    public static void main(String[] args) {
        int capacity = 30;
        int[] weights = {3, 5, 4, 10, 7, 14, 2, 11};
        int count = 0, weight = 0;
        Arrays.sort(weights);
        for (int i = 0; i < weights.length && weight < capacity; i++) {
            int newWeight = weight + weights[i];
            if (newWeight <= capacity) {
                count++;
                weight = newWeight;
            }
        }
        System.out.println(count);
    }
}
